package bb.lanxing.util;

import android.text.TextUtils;
import org.json.JSONArray;
import org.json.JSONException;

public class SectionParseUtil {
    public static int[] parse(String strSections, int count) {
        String[] split;
        int length;
        if (!TextUtils.isEmpty(strSections) && (length = (split = strSections.split(";")).length) > 0) {
            int[] iArr = new int[count];
            int i = 0;
            if (length <= count) {
                int i2 = count - length;
                while (i < length) {
                    iArr[i + i2] = Integer.parseInt(split[i]);
                    i++;
                }
            } else {
                while (i < count) {
                    iArr[i] = Integer.parseInt(split[(length - count) + i]);
                    i++;
                }
            }
            return iArr;
        }
        return null;
    }

    public static int[] parse(JSONArray jsonArray, int count) throws JSONException {
        int length;
        if (jsonArray != null && (length = jsonArray.length()) > 0) {
            int[] iArr = new int[count];
            int i = 0;
            if (length <= count) {
                int i2 = count - length;
                while (i < length) {
                    iArr[i + i2] = jsonArray.getInt(i);
                    i++;
                }
            } else {
                while (i < count) {
                    iArr[i] = jsonArray.getInt((length - count) + i);
                    i++;
                }
            }
            return iArr;
        }
        return null;
    }
}
